var MyTable={
		searchformid:"searchForm",
	    searchUrl:"/wxconfig/list",
		tableId:"lgTable",
		table:null,
		prefix:"/wxconfig"
	};
$(function() {
    var defaultColunms = MyTable.initColumn();
    var table = new BSTable(MyTable.tableId, MyTable.searchUrl,defaultColunms);
	table.setQueryParams(getFormJson(MyTable.searchForm));
	MyTable.table = table.init(0);
});
function reLoad() {
	var param = getFormJson(MyTable.searchForm);//获取查询条件
	MyTable.table.refresh(param);
}

function resetSearch(){
	cleanFormVal(MyTable.searchformid);
	MyTable.table.refresh(null);
}
function add() {
	layer.open({
		type : 2,
		title : '增加',
		maxmin : true,
		shadeClose : false, // 点击遮罩关闭层
		area : [ '800px', '520px' ],
		content : MyTable.prefix + '/add' // iframe的url
	});
}
function edit(id) {
	layer.open({
		type : 2,
		title : '编辑',
		maxmin : true,
		shadeClose : false, // 点击遮罩关闭层
		area : [ '800px', '520px' ],
		content : MyTable.prefix + '/edit/' + id // iframe的url
	});
}

function delRow(id){
    var config={
			url : MyTable.prefix+"/deleteRow",
			data:{"id":id},
			sureDo:true,
			msg:"确定删除记录？"
	}
	EasyAjax.post_json(config,function(r){
		layer.msg(r.msg);
		if (r.code == 0){
			reLoad();
		} 
	});
}
function delRows() {
		var rows=checkSelect();
		if(!rows)
		return;
		var config={
				data : {"ids" : rows},
				url : MyTable.prefix +'/deleteRows',
				sureDo:true,
				msg:"确定要删除选中的记录？"
		};
		EasyAjax.post(config,function(r){
			if (r.code == 0) {
				layer.msg(r.msg);
				reLoad();
			} else {
				layer.msg(r.msg);
			}
		});
}

function checkSelect(){
	var rows = $('#'+MyTable.tableId).bootstrapTable('getSelections'); // 返回所有选择的行，当没有选择的记录时，返回一个空数组
	if (rows.length == 0) {
		layer.msg("请选择要删除的数据");
		return null;
	}else{
		var ids = new Array();
		$.each(rows, function(i, row) {
			ids[i] = row.id;
		});
		return ids;
	}
}

MyTable.initColumn = function () {
    var columns = [
    {checkbox : true},
		{field : 'id', title : ''},
		{field : 'appid', title : 'APPID'},
		{field : 'token', title : 'TOKEN'},
		{field : 'appSecret', title : '秘钥'},
		{field : 'domain', title : '域名'},
		{field : 'mchId', title : '商户ID'},
		{field : 'paternerKey', title : '支付秘钥'},
		{field : 'certPath', title : '证书路径'},
		//{field : 'sign', title : '标识字段预留'},
		{field : 'open', title : '是否启用',formatter : function(value, row, index) {
			var str="<span style='color:green'>启用</span>";
			if(value==0){
				str="<span style='color:red'>禁用</span>";
			}
			return str;
		}},
		{
		title : '操作',
		field : 'id',
		align : 'center',
		formatter : function(value, row, index) {
			var e = '<a class="btn btn-primary btn-sm '+editBtn+'" href="#" mce_href="#" title="编辑" onclick="edit(\''
					+ row.id
					+ '\')"><i class="fa fa-edit"></i></a> ';
			var d = '<a class="btn btn-warning btn-sm '+delBtn+'" href="#" title="删除"  mce_href="#" onclick="delRow(\''
					+ row.id
					+ '\')"><i class="fa fa-remove"></i></a> ';
			var f = '<a class="btn btn-success btn-sm" href="#" title="备用"  mce_href="#" onclick="resetPwd(\''
					+ row.id
					+ '\')"><i class="fa fa-key"></i></a> ';
			return e + d ;
		}
	}
	];
    return columns;
};